home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 151-175 / scopedisk155 / zkick / romtag.asm < prev    next >
Assembly Source File  |  1995-03-19  |  8KB  |  421 lines

  1. *
  2. *    ZKick V2.10 -- Copyright (C) 1990 by Daniel Zenchelsky
  3. *
  4. *        This program may be freely copied, as long as all copyright
  5. *        notices are left intact and unchanged.
  6. *
  7.  
  8.  
  9.    SECTION   code
  10.  
  11.    NOLIST
  12.    INCLUDE "exec/types.i"
  13.    INCLUDE "exec/initializers.i"
  14.    INCLUDE "exec/libraries.i"
  15.    INCLUDE "exec/lists.i"
  16.    INCLUDE "exec/alerts.i"
  17.    INCLUDE "exec/resident.i"
  18.    INCLUDE "exec/memory.i"
  19.    INCLUDE "exec/tasks.i"
  20.    INCLUDE "libraries/expansion.i"
  21.  
  22.    INCLUDE "zkick.i"
  23.    INCLUDE "mmu.i"
  24.  
  25.    LIST
  26.  
  27.    XDEF   Reboot
  28.    XDEF   _MakeRomTag
  29.    XDEF   _config
  30.    XDEF   _connum
  31.    XDEF   _memory
  32.    XDEF   _memnum
  33.    XDEF   _Survive
  34.    XDEF   _MMU
  35.  
  36.    ;------ These don't have to be external, but it helps some
  37.    ;------ debuggers to have them globally visible
  38.    XDEF   modName
  39.    XDEF   MemName
  40.    XDEF   _InitRoutine
  41.    XDEF   initDDescrip
  42.    XDEF   ExecBase
  43.    XDEF   SaveMem
  44.    XDEF   KickMem
  45.    XDEF   KickTag
  46.    XDEF   expansionname
  47.    XDEF   ExpansionBase
  48.    XDEF   ConfigCopy
  49.    XDEF   AddMem
  50.    XDEF   EndTag
  51.  
  52.    XREF   _LVOSumKickData
  53.  
  54.    XREF   _LVOOpenLibrary
  55.    XREF   _LVOCloseLibrary
  56.    XREF   _LVOAddConfigDev
  57.    XREF   _LVOAllocConfigDev
  58.    XREF   _LVOCopyMem
  59.    XREF   _LVOAddMemList
  60.    XREF   _LVOSetFunction
  61.    XREF   _LVOSuperState
  62.    XREF   _LVOSupervisor
  63.    XREF   _LVODisable
  64.  
  65.    XREF      _ColdReboot
  66.  
  67. ;
  68. ; Offsets from ExecBase
  69. ;
  70.  
  71. KickMemPtr    EQU    $222
  72. KickTagPtr    EQU    $226
  73. KickCheckSum    EQU    $22a
  74. WarmCapture    EQU    50
  75. CoolCapture    EQU    46
  76. ColdCapture    EQU    42
  77. ExecVersion    EQU    $14
  78.  
  79. ROMVersion    EQU    $FC0010
  80.  
  81. VERSION:    EQU    2
  82. REVISION:    EQU    10
  83.  
  84.  
  85. _MakeRomTag:
  86.     move.l ExecBase,a6
  87. ;
  88. ; Set up KickMemPtr
  89. ;
  90.     lea.l KickMem+14,a0
  91.     move.w #1,(a0)+
  92.     lea.l SaveMem,a1
  93.     move.l a1,(a0)+
  94.     lea.l EndTag-SaveMem,a1
  95.     move.l a1,(a0)+
  96.     lea.l KickMem,a0
  97.     move.l a0,KickMemPtr(a6)
  98.     
  99. ;
  100. ; Set up KickTagPtr
  101. ;
  102.     lea KickTag,a0
  103.     move.l a0,KickTagPtr(a6)
  104.  
  105. ;
  106. ; Calculate checksum
  107. ;
  108.  
  109.     jsr _LVOSumKickData(a6)
  110.     move.l d0,KickCheckSum(a6)
  111. ;
  112. ; Setup reboot code
  113. ;
  114.     jsr SetVectors
  115.     rts
  116.  
  117. ;-----------------------------------------------------------------------
  118. ; From here on is protected from erasure during reboot
  119. ;-----------------------------------------------------------------------
  120.  
  121. SaveMem:
  122.  
  123. KickMem:
  124.     DC.L 0,0,0,0,0,0
  125.  
  126. KickTag:
  127.     DC.L    initDDescrip
  128.     DC.L    $0
  129.  
  130. OldAddMemList:    DC.L    $00000000
  131. _Survive:    DC.L    $00000000
  132. _MMU:        DC.L    $00000000
  133.  
  134. ;
  135. ; Set up the reboot routines
  136. ;
  137.  
  138. SetVectors:
  139.  
  140.     lea.l ColdRoutine,a0
  141.     move.l a0,ColdCapture(a6)
  142.  
  143.     lea.l CoolRoutine,a0
  144.     move.l a0,CoolCapture(a6)
  145.  
  146. ; Recalculate checksum
  147.  
  148.     lea $22(a6),a0
  149.     moveq #$16,d0
  150.     moveq #0,d1
  151. sumloop:
  152.     add.w (a0)+,d1
  153.     dbra d0,sumloop
  154.     not.w d1
  155.     move.w d1,$52(a6)
  156.  
  157.     rts
  158.  
  159. ColdRoutine:
  160.     
  161.     cmp.l #$B7FC0004,$1e(a5)    ; Verify that this is really 1.2/1.3
  162.     bne.s skipfix
  163.     move.l $3E(A6),A3        ; Skip version and >512k chip mem
  164.     jmp $1e(a5)            ; checks
  165.  
  166. skipfix:
  167.     jmp (a5)
  168.  
  169. CoolRoutine:
  170.     move.l ExecBase,a6
  171.     
  172.     movea.l a6,a1            ; Keep exec from stomping
  173.     lea.l NewAddMemList,a0        ; on the first few bytes
  174.     move.l a0,d0            ; of kickstart memory.
  175.     lea.l _LVOAddMemList,a0
  176.     jsr _LVOSetFunction(a6)
  177.     move.l d0,OldAddMemList
  178.  
  179.     rts
  180.  
  181. NewAddMemList:
  182.  
  183.     rts
  184.  
  185. ;-----------------------------------------------------------------------
  186. ; A romtag structure.  Both "exec" and "ramlib" look for
  187. ; this structure to discover magic constants about you
  188. ; (such as where to start running you from...).
  189. ;-----------------------------------------------------------------------
  190.  
  191.    ; Most people will not need a priority and should leave it at zero.
  192.    ; the RT_PRI field is used for _configuring the roms.  Use "mods" from
  193.    ; wack to look at the other romtags in the system
  194.  
  195. MYPRI   EQU   107     
  196.  
  197. initDDescrip:
  198.                ;STRUCTURE RT,0
  199.      DC.W    RTC_MATCHWORD      ; UWORD RT_MATCHWORD
  200.      DC.L    initDDescrip       ; APTR  RT_MATCHTAG
  201.      DC.L    EndTag             ; APTR  RT_ENDSKIP
  202.      DC.B    RTF_COLDSTART      ; UBYTE RT_FLAGS
  203.      DC.B    VERSION            ; UBYTE RT_VERSION
  204.      DC.B    NT_UNKNOWN         ; UBYTE RT_TYPE
  205.      DC.B    MYPRI              ; BYTE  RT_PRI
  206.      DC.L    modName            ; APTR  RT_NAME
  207.      DC.L    idString           ; APTR  RT_IDSTRING
  208.      DC.L    _InitRoutine       ; APTR  RT_INIT
  209.  
  210.  
  211.    ; this is the name that the module will have
  212. modName:    DC.B   'zkick.romtag',0
  213.  
  214. idString:   dc.b   'zkick.romtag 2.0 (8/11/90)',13,10,0
  215.  
  216. MemName:    dc.b  'zkick memory',0
  217.  
  218. expansionname:    dc.b  'expansion.library',0
  219.  
  220.     CNOP 0,4
  221.  
  222. ExecBase    EQU     $00000004
  223. ExpansionBase:    DC.L     $00000000
  224. ConfigCopy:    DC.L     $00000000
  225.  
  226.  
  227. _InitRoutine:
  228.  
  229.     movem.l d0-d6/a0-a6,-(a7)
  230.  
  231.     move.l ExecBase,a6            ; If we're running under 1.2/1.3
  232.     move.l ROMVersion,a0        ; we wan't to start KickStart
  233.     cmp.l ExecVersion(a6),a0        ; from $200000
  234.     bne okversion
  235.  
  236.     lea.l    $200000,a0        ; Checksum KickStart image
  237.     move.l    #$80000,d1        ; at $200000
  238.     jsr     CheckSum
  239.     cmp.l    #0,d0
  240.     bne.s    panic
  241.                             ; Let's be doubly cautious:
  242.     jsr     _LVOSuperState(a6)
  243.     lea    $200000,a0            ; Verify that there's a
  244.     move.l    (a0),d0            ; KickStart image at
  245.     cmp.w    #$4ef9,2(a0)        ; $200000
  246.     bne.s    panic
  247.  
  248.     move.l    ExecBase,a6        ; If there is an MMU
  249.     jsr        _LVODisable(a6)    ; disable it before
  250.     cmp.l    #0,_MMU            ; starting KickStart
  251.     beq        1$
  252.     move.l    #0,a0
  253.     jsr        SetTC
  254.  
  255. 1$:    jmp    2(a0)                ; Start KickStart
  256.  
  257. panic:                        ; Uh oh, doesn't look like
  258.     move.l    #0,ColdCapture(a6)    ; KickStart at $200000
  259.     move.l    #0,CoolCapture(a6)
  260.     move.l    #0,WarmCapture(a6)    ; Clear vectors and reboot
  261.     move.l    #0,KickTagPtr(a6)
  262.     move.l    #0,KickMemPtr(a6)
  263.  
  264.     jmp Reboot
  265.     
  266. okversion:
  267.  
  268.     cmp.l #0,_Survive        ; Do we want to survive?
  269.     beq.s 2$
  270.     jsr SetVectors            ; Set up Capture vectors
  271.                         ; for reboot survival
  272.  
  273. 2$:    lea.l expansionname,A1
  274.     move.l #0,D0    
  275.     jsr _LVOOpenLibrary(a6)        ; Open expansion.library
  276.     move.l D0,ExpansionBase
  277.     cmp.l #0,D0
  278.     bne.s 1$
  279.     jmp exit
  280.  
  281. 1$:
  282.     lea.l _config,a2
  283.     move.l _connum,a3
  284.  
  285. loop:    cmp.l #0,a3
  286.     beq.s close
  287.  
  288.     move.l ExpansionBase,a6        ; For each configdev structure we
  289.     jsr _LVOAllocConfigDev(a6)    ; saved, allocate a fresh configdev
  290.     move.l D0,ConfigCopy        ; structure.
  291.     cmp.l #0,D0
  292.     bne.s 2$
  293.     jmp close
  294.  
  295. 2$:    
  296.     move.l a2,A0
  297.     move.l ConfigCopy,A1        ; Copy the old configdev onto
  298.     move.l #end_config-_config,D0    ; the new one
  299.     move.l ExecBase,a6
  300.     jsr _LVOCopyMem(a6)
  301.  
  302.     move.l ConfigCopy,A0
  303.     move.l ExpansionBase,a6
  304.     jsr _LVOAddConfigDev(a6)        ; Add it to the configdev list
  305.  
  306.     sub.l #1,a3
  307.     add.l #end_config-_config,a2    ; Go get another configdev structure
  308.     jmp loop
  309.  
  310. close:
  311.     move.l ExpansionBase,A1
  312.     move.l ExecBase,a6        ; Close expansion.library
  313.     jsr _LVOCloseLibrary(a6)
  314.  
  315. AddMem:
  316.  
  317.     lea _memory,a2            ; Do the same thing
  318.     move.l _memnum,a3        ; for the memory lists
  319.  
  320. 1$:    cmp.l #0,a3
  321.     beq.s exit
  322.  
  323.     move.l (a2),a0
  324.     add.l #4,a2
  325.     move.l (a2),d0
  326.     add.l #4,a2
  327.     move.l #MEMF_FAST+MEMF_PUBLIC,d1
  328.     move.l #0,d2
  329.     lea.l MemName,a1
  330.     move.l ExecBase,a6
  331.     jsr _LVOAddMemList(a6)
  332.     
  333.     sub.l #1,a3
  334.     jmp 1$
  335.  
  336. exit:
  337.     movem.l (a7)+,d0-d6/a0-a6
  338.     rts
  339.  
  340. CheckSum:
  341.     lsr.l    #2,d1
  342.     subq.l    #1,d1
  343.     moveq    #0,d0
  344.  
  345. 1$:    add.l    (a0)+,d0
  346.     bcc.s    2$
  347.     addq.l    #1,d0
  348.  
  349. 2$:    dbra    d1,1$
  350.     sub.l    #$10000,d1
  351.     bpl.s    1$
  352.     addq.l    #1,d0
  353.     rts
  354.  
  355. ;======================================================================
  356. ;
  357. ;    This function sets the MMU TC register.  It assumes a 68020 
  358. ;    system with MMU, or a 68030 based system (eg, test for MMU before
  359. ;    you call this, or you wind up in The Guru Zone).  
  360. ;
  361. ;    SetTC(ULONG)
  362. ;        a0
  363. ;======================================================================
  364.  
  365. SetTC:
  366.     move.l    4,a6                ; Get ExecBase
  367.     move.l    a5,-(sp)
  368.     lea.l    1$,a5            ; Get the start of the supervisor code
  369.      CALLSYS    Supervisor
  370.     move.l    (sp)+,a5
  371.     rts
  372. 1$
  373.     _PMOVE    (a0),tc            ; Just set the TC register
  374.     rte
  375.  
  376. Reboot:
  377.     move.l    ExecBase,a6        ; If there is an MMU,
  378.     jsr        _LVODisable(a6)    ; disable it before
  379.     cmp.l    #0,_MMU            ; rebooting.
  380.     beq        nommu
  381.     move.l    #0,a0
  382.     jsr        SetTC
  383. nommu:
  384.     jmp        _ColdReboot
  385.  
  386. EndCode:
  387.  
  388. *********
  389.  
  390.     CNOP 0,4    ; LongWord Align (For CopyMem)
  391.  
  392. _connum:    DC.L 0
  393.  
  394. _config:
  395.     DC.L 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  396. end_config:
  397.     DC.L 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  398.     DC.L 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  399.     DC.L 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  400.     DC.L 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  401.     DC.L 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  402.     DC.L 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  403.     DC.L 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  404.  
  405. _memnum:    DC.L 0
  406.  
  407. _memory:
  408.     DC.L 0,0
  409. end_memory:
  410.     DC.L 0,0
  411.     DC.L 0,0
  412.     DC.L 0,0
  413.     DC.L 0,0
  414.     DC.L 0,0
  415.     DC.L 0,0
  416.     DC.L 0,0
  417.  
  418. EndTag:
  419.  
  420.    END
  421.